define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    // del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#money").text(data.money);
                $("#money2").text(data.money2);

            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'tpye', title: __('类型'), searchList: {"1":__('Tpye 1'),"2":__('Tpye 2'),"3":__('Tpye 3')}, formatter: Table.api.formatter.normal},
                        {field: 'user.nickname', title: __('用户昵称'), operate: 'LIKE'},
                        {field: 'top_nickname', title: __('推荐人')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        
                        

                        // {field: 'pay_sn', title: __('Pay_sn'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'company_id', title: __('Company_id')},
                        // {field: 'company_sn', title: __('Company_sn'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'goods_total', title: __('Goods_total'), operate:'BETWEEN'},
                        // {field: 'freight_total', title: __('Freight_total'), operate:'BETWEEN'},
                        {field: 'order_total', title: __('Order_total'), operate:'BETWEEN'},

                        // {field: 'pay_total', title: __('Pay_total'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('支付审核中'),"7":__('支付失败'),"8":__('拼团中')}, formatter: Table.api.formatter.status},



                        // {field: 'pay_image', title: __('Pay_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'pay.name', title: __('支付方式')},

                        // {field: 'pay.state_text', title: __('是否审核')},

                        {field: 'pay_type', title: __('Pay_type'), searchList: {"wechat":__('Pay_type wechat'),"alipay":__('Pay_type alipay')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'deliverytime', title: __('Deliverytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        // {field: 'taketime', title: __('Taketime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},


                        // {field: 'company.name', title: __('Company.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'),

                            table: table, events: Table.api.events.operate,
                            buttons: [
                            //     {
                            //     name: 'pass',
                            //     title: __('小程序发货'),
                            //     classname: 'btn btn-xs btn-warning  btn-magic btn-ajax',
                            //     icon: 'fa fa-check',
                            //     text: '小程序发货',
                            //     confirm: '确认点击同意，小程序发货',
                            //     url: 'order/setOrderStatus',
                            //     visible: function(row) {
                            //         // 审核:0=提交资质,1=提交店铺,2=提交审核,3=通过,4=未通过
                            //         if (row.send_goods == 0 ) {
                            //             return true;
                            //         }
                            //     },
                            //     success: function(data, ret) {
                            //         Layer.alert(ret.msg);
                            //         table.bootstrapTable('refresh');
                            //         return false;
                            //     },
                            //     error: function(data, ret) {
                            //         console.log(data, ret);
                            //         Layer.alert(ret.msg);
                            //         return false;
                            //     }
                            // },

                                // {
                                //     name: 'refuse',
                                //     title: __('审核拒绝'),
                                //     classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                //     icon: 'fa fa-close',
                                //     text: '审核拒绝',
                                //     confirm: '确认点击同意，审核拒绝',
                                //     url: 'order/change?status=7',
                                //     visible: function(row) {
                                //         // 审核:0=提交资质,1=提交店铺,2=提交审核,3=通过,4=未通过
                                //         if (row.status == 6 ) {
                                //             return true;
                                //         }
                                //     },
                                //     success: function(data, ret) {
                                //         Layer.alert(ret.msg);
                                //         table.bootstrapTable('refresh');
                                //         return false;
                                //     },
                                //     error: function(data, ret) {
                                //         console.log(data, ret);
                                //         Layer.alert(ret.msg);
                                //         return false;
                                //     }
                                // },
                                {

                                    name: 'detail',
                                    title: __('详情'),
                                    text: '详情',
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'order/detail'
                                },
                                // {
                                //     name: 'ajax',
                                //     title: __('线下核销'),
                                //     text: "线下核销",
                                //     classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                //     icon: 'fa fa-magic',
                                //     confirm: '确认选择线下核销？',
                                //     url: 'order/xianxiahexiao',
                                //     success: function (data, ret) {
                                //         // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                //         //如果需要阻止成功提示，则必须使用return false;
                                //         location.reload();
                                //         //return false;
                                //     },
                                //     error: function (data, ret) {
                                //         console.log(data, ret);
                                //         Layer.alert(ret.msg);
                                //         return false;
                                //     }
                                // },
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
